<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="./lib/react.js"></script>
    <script src="./lib/react_dom.js"></script>
    <script src="./lib/babel.js"></script>

    <script type="text/babel">
      class App extends React.Component {
        constructor() {
          super()
          this.state = {
            message: 'hello world',
            isShow: true,
          }
        }

        btnClick() {
          this.setState({
            isShow: !this.state.isShow,
          })
        }

        render() {
          const { isShow, message } = this.state

          let showElement = null
          if (isShow) {
            showElement = <h2>{message}</h2>
          }

          return (
            <div>
              {isShow && <div>{message}</div>}

              <div style={{ display: isShow ? 'block' : 'none' }}>
                {message}
              </div>
              <button onClick={() => this.btnClick()}>显示隐藏切换</button>
            </div>
          )
        }
      }

      const root = ReactDOM.createRoot(document.querySelector('#root'))
      root.render(<App />)
    </script>
  </body>
</html>
